package com.jch.dm.chapter_23_interpreter;

/**
 * @author: Administrator
 * <primitive command> ::= go | right | left
 * @create: 2020/04/14 18:30
 **/
public class PrimitiveCommandNode extends Node {

    private String name;

    /**
     * 解析
     *
     * @param context
     * @throws ParseException
     */
    @Override
    public void parse(Context context) throws ParseException {
        name = context.currentToken();
        context.skipToken(name);
        if (!name.equals("go")&& !name.equals("right") && !name.equals("left")){
            throw new ParseException(name + " is undefined");
        }
    }

    @Override
    public String toString(){
        return name;
    }
}
